<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/wpui-admin/wp-ewallet-admin/static/plugin/layuimini/lib/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/wpui-admin/wp-ewallet-admin/static/plugin/layuimini/css/public.css" media="all">

    <style>
        .table-row-bar{
            padding: 0px 5px;
            cursor: pointer;
        }
    </style>
</head>
<body>
<div id="container" class="layuimini-container">
    <div class="layuimini-main">

        <h2><b>理财产品列表</b></h2>

        <div style="margin: 10px 0px 10px 0px">
            <form class="layui-form" action="">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label" style="padding: 9px 15px 9px 0px;">产品名称：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="finaProdName" autocomplete="off" class="layui-input" v-model="finaProdName">
                        </div>
                    </div>

                    <div class="layui-inline" style="float: right;margin-right:0px;">
                        <a class="layui-btn layui-btn-normal" lay-submit="" style="width: 100px;" lay-filter="data-search-btn">查询</a>
                        <a class="layui-btn layui-btn-normal" lay-submit="" style="width: 100px;" lay-filter="data-create-btn">创建</a>
                    </div>
                </div>
            </form>
        </div>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
    </div>
</div>

<!-- Vue 表达式与Layui模板表达式冲突，需放在Vue Scope 外边 -->
<script type="text/html" id="operTpl">
    {{#  if(d.status == '1200'){ }}
    <a class="table-row-bar" lay-event="edit" style="color: #1890FF;">编辑</a>
    <a class="table-row-bar" lay-event="up"   style="color: #1890FF;">上架</a>
    <a class="table-row-bar" lay-event="down" style="color: #A5A5A5;">下架</a>
    {{#  } else if(d.status == '1000') { }}
    <a class="table-row-bar" lay-event="edit" style="color: #A5A5A5;">编辑</a>
    <a class="table-row-bar" lay-event="up"   style="color: #A5A5A5;">上架</a>
    <a class="table-row-bar" lay-event="down" style="color: #FF0000;">下架</a>
    {{#  } else { }}
    <a class="table-row-bar" lay-event="edit" style="color: #A5A5A5;">编辑</a>
    <a class="table-row-bar" lay-event="up"   style="color: #1890FF;">上架</a>
    <a class="table-row-bar" lay-event="down" style="color: #A5A5A5;">下架</a>
    {{#  } }}
</script>

<script type="text/html" id="openDetailTpl">
    <a style="cursor: pointer;" lay-event="detail">{{d.finaProdName}}</a>
</script>

<script type="text/html" id="idTpl">
    <a style="color: #1890FF;cursor: pointer;" lay-event="detail">{{d.finaProdId}}</a>
</script>

<script type="text/html" id="yieldRateTpl">
    <a lay-event="detail">{{Math.round((d.yieldRate*100)*1000)/1000 + '%'}}</a>
</script>

<script type="text/html" id="statusTpl">
    {{#  if(d.status === '1200'){ }}
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="edit">待上架</a>
    {{#  } else if(d.status === '1000') { }}
    <a class="layui-btn layui-btn-xs" lay-event="up" >已上架</a>
    {{#  } else { }}
    <a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="down">已下架</a>
    {{#  } }}
</script>

<script src="/wpui-admin/wp-ewallet-admin/static/js/jquery-3.4.1.min.js"></script>
<script src="/wpui-admin/wp-ewallet-admin/static/plugin/layuimini/lib/layui/layui.js" charset="utf-8"></script>
<script src="/wpui-admin/wp-ewallet-admin/module/index/config.js" charset="utf-8"></script>
<script src="/wpui-admin/wp-ewallet-admin/global/wp.js" charset="utf-8"></script>
<script src="/wpui-admin/wp-ewallet-admin/static/js/vue.js" charset="utf-8"></script>
<script src="/wpui-admin/wp-ewallet-admin/static/js/vue-i18n.js" charset="utf-8"></script>
<script src="/wpui-admin/wp-ewallet-admin/global/wp-i18n.js" charset="utf-8"></script>
<script src="/wpui-admin/wp-ewallet-admin/global/wp-project.js" charset="utf-8"></script>

<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        var vm = new Vue({
            el: '#container',
            i18n: wp.i18n(),
            data: {
                finaProdName:''
            },
            mounted:function(){
                this.init();
                this.grid();
                this.createEvent();
                this.searchEvent();
            },
            methods: {
                init:function(){
                    // 监听添加操作
                    $(".data-add-btn").on("click", function () {
                        layer.msg('添加数据');
                    });

                    // 监听删除操作
                    $(".data-delete-btn").on("click", function () {
                        var checkStatus = table.checkStatus('currentTableId')
                            , data = checkStatus.data;
                        layer.alert(JSON.stringify(data));
                    });
                },
                grid:function(){
                    var that = this;
                    table.render({
                        elem: '#currentTableId',
                        url: '/wp/ewallet/wmps/finaProd/getAllFinaProdInfoList',
                        headers:wp.getAjaxHeaders(),
                        parseData: wp.parseGridData,
                        cols: [[
                            {title: '操作', templet: '#operTpl', fixed: "left", align: "center", width: 180},
                            {field: 'finaProdId', title: '产品ID', templet : '#idTpl', width: 180},
                            {field: 'finaProdName', title: '产品名称', templet : '#openDetailTpl'},
                            {field: 'status', title: '产品状态', templet: '#statusTpl', width: 120},
                            {field: 'yieldRate', title: '年收益', templet: '#yieldRateTpl', width: 120},
                            {field: 'minPurchAmount', title: '最低起购额', width: 150},
                            {field: 'finaProdCycle', title: '理财周期', width: 120}
                        ]],
                        limits: wp.config.pageList,
                        limit: wp.config.pageSize,
                        page: true
                    });

                    table.on('tool(currentTableFilter)', function (obj) {
                        var data = obj.data;
                        if (obj.event === 'edit' && '1200' === data.status) {
                            that.editEvent(data);
                        } else if (obj.event === 'down' && '1000' === data.status) {
                            that.downEvent(data);
                        } else if (obj.event === 'up' && '1100' === data.status) {
                            that.upEvent(data);
                        }else if(obj.event === 'detail'){
                            that.openDetail(data);
                        }
                    });
                },
                upEvent: function(data){
                    var that = this;
                    layer.confirm("请确认是否上架该理财产品?", {title:"提示信息",icon:0}, function(index) {
                        layer.close(index);
                        var loading = wp.loading();
                        wp.httpPost({
                            url: wp.url('/wp/ewallet/wmps/finaProd/upperFinaProdInfo'),
                            data: {
                                finaProdId: data.finaProdId
                            },
                            success: function (data) {
                                wp.closeLoading();
                                that.reloadGrid();
                                layer.msg('操作成功');
                            },
                            failure: function (data) {
                                wp.closeLoading();
                                layer.msg('操作失败');
                            }
                        });
                    });
                },
                downEvent: function(data){
                    var that = this;
                    layer.confirm("请确认是否下架该理财产品?", {title:"提示信息",icon:0}, function(index) {
                        layer.close(index);
                        var loading = wp.loading();
                        wp.httpPost({
                            url: wp.url('/wp/ewallet/wmps/finaProd/lowerFinaProdInfo'),
                            data: {
                                finaProdId: data.finaProdId
                            },
                            success: function (data) {
                                wp.closeLoading();
                                that.reloadGrid();
                                layer.msg('操作成功');
                            },
                            failure: function (data) {
                                wp.closeLoading();
                                layer.msg('操作失败');
                            }
                        });
                    });
                },
                reloadGrid:function(){
                    var that = this;
                    //执行搜索重载
                    table.reload('currentTableId', {
                        page: {
                            curr: 1
                        }
                        , where: {
                            finaProdName: that.finaProdName
                        }
                    }, 'data');
                },
                createEvent:function(){
                    var self = this;
                    // 监听搜索操作
                    form.on('submit(data-create-btn)', function (data) {
                        var result = JSON.stringify(data.field);
                        // 添加到tab
                        var iframeWindow = wp.addTab(wp.resUrl('/wpui-admin/wp-ewallet-admin/module/wmps/wmps-form.html'),"创建理财产品");
                        iframeWindow.walletApplyVm = self;
                        // 窗口关闭方法
                        iframeWindow.close = function(){
                            wp.closeTab(iframeWindow.tabId);
                        }
                        iframeWindow.onLoadFinish = function(vm){

                        }

                        return false;
                    });
                },
                editEvent:function(data){
                    var self = this;
                    // 添加到tab
                    var iframeWindow = wp.addTab(wp.resUrl('/wpui-admin/wp-ewallet-admin/module/wmps/wmps-form-edit.html'),"编辑理财产品");

                    iframeWindow.walletApplyVm = self;
                    iframeWindow.data = data;
                    // 窗口关闭方法
                    iframeWindow.close = function(){
                        wp.closeTab(iframeWindow.tabId);
                    }
                    iframeWindow.onLoadFinish = function(vm){

                    }
                },
                searchEvent:function(){
                    // 监听搜索操作
                    form.on('submit(data-search-btn)', function (data) {
                        var result = data.field;
                        //执行搜索重载
                        table.reload('currentTableId', {
                            page: {
                                curr: 1
                            }
                            , where: {
                                finaProdName: result.finaProdName
                            }
                        }, 'data');

                        return false;
                    });
                },
                openDetail:function(data){
                    var self = this;
                    // 添加到tab
                    var iframeWindow = wp.addTab(wp.resUrl('/wpui-admin/wp-ewallet-admin/module/wmps/wmps-detail.html'),"理财产品详情");

                    iframeWindow.wmpsApplyVm = self;
                    iframeWindow.data = data;
                    // 窗口关闭方法
                    iframeWindow.close = function(){
                        wp.closeTab(iframeWindow.tabId);
                    }
                    iframeWindow.onLoadFinish = function(vm){

                    }
                }
            }
        });
    });
</script>
<script>

</script>

</body>
</html>